package com.ln.lnzw.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.ActivityUtils;
import com.ln.lnzw.R;
import com.ln.lnzw.adapter.CommonProblemAdapter;
import com.ln.lnzw.adapter.ExpandableItemAdapter;
import com.ln.lnzw.app.AppConstant;
import com.ln.lnzw.base.BaseActivity;
import com.ln.lnzw.bean.CommonProblemBean;
import com.ln.lnzw.bean.WcmBean;
import com.ln.lnzw.net.HttpMethods;
import com.ln.lnzw.utils.ImageUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by wuwei on 2018/4/25.
 * 互动交流
 */

public class InteractionActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.image)
    ImageView image;
    @BindView(R.id.ll_yonghujianyi)
    LinearLayout llYonghujianyi;
    @BindView(R.id.ll_yonghutousu)
    LinearLayout llYonghutousu;
    @BindView(R.id.ll_fuwupingjia)
    LinearLayout llFuwupingjia;
    @BindView(R.id.ll_zaixiandiaocha)
    LinearLayout llZaixiandiaocha;
    @BindView(R.id.rv_recyclerview)
    RecyclerView rvRecyclerview;
    private CommonProblemAdapter myAdapter;
    private List<CommonProblemBean.ListDatasBean> mList =new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interaction);
        ButterKnife.bind(this);
        ImageUtil.suitDisplayWideFill(image, 18, 5);
        setView();

    }

    private void initData() {
        HttpMethods.getInstance().info.getCommonProblem(AppConstant.COMMON_PROBLEM_URL)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<CommonProblemBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(CommonProblemBean commonProblemBean) {
                            if (mList != null) {
                                mList.clear();
                            }
                          if ("200".equals(commonProblemBean.getCode())){
                              mList.addAll(commonProblemBean.getList_datas());
                          }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {
                        myAdapter.notifyDataSetChanged();
                    }
                });


    }

    private void setView() {
        myAdapter = new CommonProblemAdapter(R.layout.item_common_problem,mList);
        rvRecyclerview.setLayoutManager(new LinearLayoutManager(this));
//        rvRecyclerview.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
        rvRecyclerview.setAdapter(myAdapter);
        initData();

    }


    @OnClick({R.id.ll_yonghujianyi, R.id.ll_yonghutousu, R.id.ll_fuwupingjia, R.id.ll_zaixiandiaocha,R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_yonghujianyi:
                ActivityUtils.startActivity(activity,UserSuggestionActivity.class);
                break;
            case R.id.ll_yonghutousu:
                ActivityUtils.startActivity(activity,UserComplaintsActivity.class);
                break;
            case R.id.ll_fuwupingjia:
                break;
            case R.id.ll_zaixiandiaocha:
                break;
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
